package com.link2room.quintesson.nmsrunner;

import com.aliyun.mns.model.Message;
import com.link2room.common.enums.BaseSysExceptionEnum;
import com.link2room.common.mns.Worker;
import com.link2room.common.util.BatchUtil;
import com.link2room.common.util.ExceptionUtil;
import com.link2room.common.util.JacksonUtil;
import com.link2room.common.util.LogUtil;
import com.link2room.quintesson.dto.param.manager.TaobaoHotelRateplanManagerParamDto;
import com.link2room.quintesson.facade.ITaobaoHotelRateplanFacadeService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * Created by sss on 2016/9/21.
 */
@Component("taobaoXrateplanRunner")
public class TaobaoXrateplanRunnerImpl implements Worker {
    @Resource
    private ITaobaoHotelRateplanFacadeService taobaoHotelRateplanFacadeService;

    @Override
    public boolean exec(Message message) throws Exception {
        try{
            TaobaoHotelRateplanManagerParamDto taobaoHotelRateplanManagerParamDto = JacksonUtil.jsonToBean(message.getMessageBody(), TaobaoHotelRateplanManagerParamDto.class);
            if(message.getDequeueCount()>3){
                BatchUtil.doBatchTaskFail(taobaoHotelRateplanManagerParamDto.getTaskMainId(),taobaoHotelRateplanManagerParamDto.getTaskId(),BaseSysExceptionEnum.MNS_COUNT_ABOVE.getMsg());
            }else {
                taobaoHotelRateplanFacadeService.upTaobaoXrateplan(taobaoHotelRateplanManagerParamDto);
            }
            return true;
        }catch (Exception e){
            LogUtil.logger.error(ExceptionUtil.getExceptionDetail(e));
            return false;
        }
    }
}
